﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MobileServices;

using Coder.Framework.Structures;

namespace Coder.Framework
{
    public class AzureClient
    {
        
        //Represents a Azure Mobile Service which allows editing of SQL Tables.
        public MobileServiceClient MobileService;


        public AzureClient()
        {
            MobileService = new MobileServiceClient(
                "https://coder.azure-mobile.net/",
                "iuLNZZhdejCjLPxTPfgzeEySSvSKaG24");
        }

        /// <summary>
        /// Retrieves A List of Messages for a Chat Room.
        /// </summary>
        public async Task<List<Message>> RetrieveMessages()
        {
            return await MobileService.GetTable<Message>().ToListAsync();
        }
        
        /// <summary>
        /// Retrieves A List of LeaderboardItems for a Leaderboard.
        /// </summary>
        public async Task<List<LeaderboardItem>> RetrieveLeaderboard()
        {
            return await MobileService.GetTable<LeaderboardItem>().ToListAsync();
        }

        /// <summary>
        /// Inserts a Message into the Chat Room.
        /// </summary>
        public async Task AddMessage(Message message)
        {
            await MobileService.GetTable<Message>().InsertAsync(message);
        }

        /// <summary>
        /// Attempts to insert a Leaderboard Item into the Leaderboard.
        /// </summary>
        public async Task PostLeaderboardItem(LeaderboardItem item)
        {
            await MobileService.GetTable<LeaderboardItem>().InsertAsync(item);
        }

        
    }
}
